package cn.easybuy.service.order;

import java.util.List;
import java.util.UUID;

import org.junit.Test;

import cn.easybuy.dao.OrderDao;
import cn.easybuy.dao.impl.OrderDaoImpl;
import cn.easybuy.entity.Order;
import cn.easybuy.utils.DataSourceUtil;

public class OrderServiceImpl implements OrderService {

	@Override
	public int addOrder(Order o) {
		OrderDao odao=new OrderDaoImpl(DataSourceUtil.getConnection());
		o.setSerialNumber(this.getGUID());
		System.out.println("当前订单号为："+o.getSerialNumber());
		return odao.addOrder(o);
	}
	//生成订单号
	public String getGUID(){
		return UUID.randomUUID().toString().toUpperCase().replaceAll("-", "-");
	}
	@Test
	public void test(){
		String s = this.getGUID();
		System.out.println(s);
	}
	@Override
	public Order selOrder(int id) {
		OrderDao odao=new OrderDaoImpl(DataSourceUtil.getConnection());
		return odao.selOrder(id);
	}

	@Override
	public List<Order> getOrders(int pageNo, int pageSize) {
		OrderDao odao=new OrderDaoImpl(DataSourceUtil.getConnection());
		return odao.getOrders(pageNo, pageSize);
	}

	@Override
	public List<Order> myOrdrs(String userId) {
		OrderDao odao=new OrderDaoImpl(DataSourceUtil.getConnection());
		return odao.myOrdrs(userId);
	}
	@Override
	public int getCount() {
		OrderDao odao=new OrderDaoImpl(DataSourceUtil.getConnection());
		return odao.getCount();
	}
	@Override
	public int del(String id) {
		OrderDao odao=new OrderDaoImpl(DataSourceUtil.getConnection());
		return odao.del(id);
	}

}
